<template>
  <div>
    <el-table
      :data="msglist"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="用户编号">
      </el-table-column>
        <el-table-column prop="username" label="用户名">
      </el-table-column>
      <el-table-column prop="rolename" label="所属角色">
      </el-table-column>
      <el-table-column prop="address" label="状态">
        <template v-slot="scoped">
          <div>
            <el-button type="success" v-if="scoped.row.status == 1"
              >启用</el-button
            >
            <el-button type="info" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
           <template v-slot="scoped">
          <div>
            <el-button @click="edit(scoped.row.uid)">编辑</el-button>
            <el-button @click="del(scoped.row.uid)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页
background      背景颜色
layout          布局
total           总条数
page-size       每页展示多少条
-->
<el-pagination background layout="prev, pager, next" :total="msgTotal" :page-size="msgSize" 
@current-change="changePage">
</el-pagination>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {msgDel} from "../../../request/api.js";
import {sucessAlert,warningAlert} from "../../../utils/alert.js"
export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      msglist:"manage/list",
      //总条数
      msgTotal:"manage/total",
      //每页多少条
      msgSize:"manage/size"
    }),
  },
  methods: {
    ...mapActions({
      msgasynclist:"manage/asyncList",
      msgasyncTotal:"manage/asyncTotal",
      msgasyncPage:"manage/asyncPage"
    }),
    edit(uid){
      this.$emit("emit",uid)
    },
    del(uid){
         this.$confirm('此操作将永久删除该文件，是否继续？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type:"warning"
        }).then(() =>
         {
                //点击成功
          msgDel({
                  uid:uid
                }).then(res=>{
                    if(res.data.code == 200){
                // 成功的提示窗
                sucessAlert(res.data.msg),
                // 刷新列表数据
               this.msgasynclist()
            }else{
                // 失败的提示窗
                warningAlert(res.data.msg)
            }
                })
          }).catch(()=> {

            // 如果走的catch说明点的是取消
             warningAlert("已取消删除")
          
          });
      },
      changePage(e){
        this.msgasyncPage(e)
      }
  },
  mounted() {
    this.msgasyncTotal(),
    this.msgasyncPage(1)
  },
};
</script>
<style scoped>
</style>